using System;
using System.Net.Security;
using Godot;
public static class RectUtil
{
    public static (float, float) ToWHTuple(this Rect2 r)
    {
        return (r.Size.x, r.Size.y);
    }
    public static (float, float) ToXYTuple(this Rect2 r)
    {
        return (r.Position.x, r.Position.y);
    }
    public static (float, float, float, float) ToXYWHTuple(this Rect2 r)
    {
        return (r.Position.x, r.Position.y, r.Size.x, r.Size.y);
    }
    public static (float, float, float, float) ToLTRBTuple(this Rect2 r)
    {
        return (r.Position.x, r.Position.y, r.End.x, r.End.y);
    }
    public static Vector2 TopLeft(this Rect2 r, float offset_x = 0, float offset_y = 0)
    {
        return r.Position + new Vector2(offset_x, offset_y);
    }
    public static Vector2 TopRight(this Rect2 r, float offset_x = 0, float offset_y = 0)
    {
        return new Vector2(r.End.x + offset_x, r.Position.y + offset_y);
    }
    public static Vector2 BottomLeft(this Rect2 r, float offset_x = 0, float offset_y = 0)
    {
        return new Vector2(r.Position.x + offset_x, r.End.y + offset_y);
    }
    public static Vector2 BottomRight(this Rect2 r, float offset_x = 0, float offset_y = 0)
    {
        return r.End + new Vector2(offset_x, offset_y);
    }
    public static Rect2 ExtendFromRB(this Rect2 r, Vector2 rb)
    {
        r.Size = rb - r.Position;
        return r;
    }

    internal static Rect2 FromLTRB(Vector2 min, Vector2 max)
    {
        var xMin = Math.Min(min.x, max.x);
        var xMax = Math.Max(min.x, max.x);
        var yMin = Math.Min(min.y, max.y);
        var yMax = Math.Max(min.y, max.y);
        return new Rect2(xMin, yMin, xMax - xMin, yMax - yMin);
    }
}

public static class VectorUtil
{
    public static (float, float) ToTuple(this Vector2 v)
    {
        return (v.x, v.y);
    }

}